package DingBaiLu;

//丁白露

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

public class DoubleColorBall {
    public static void main(String[] args) {
        int[] winningNumbers = generateWinningNumbers();
        int[] userNumbers = getUserInput();

        int redBallMatch = countRedBallMatch(winningNumbers, userNumbers);
        int blueBallMatch = (winningNumbers[6] == userNumbers[6]) ? 1 : 0;

        System.out.println("中奖号码为：");
        printNumbers(winningNumbers);
        System.out.println("您投注号码为：");
        printNumbers(userNumbers);
        System.out.println("您命中了" + redBallMatch + "个红色球号码，" + blueBallMatch + "个蓝色球号码。");

        String prizeLevel = determinePrizeLevel(redBallMatch, blueBallMatch);
        System.out.println(prizeLevel);
    }

    public static int[] generateWinningNumbers() {
        Random random = new Random();
        List<Integer> redBalls = new ArrayList<>();
        while (redBalls.size() < 6) {
            int num = random.nextInt(33) + 1;
            if (!redBalls.contains(num)) {
                redBalls.add(num);
            }
        }
        int blueBall = random.nextInt(16) + 1;
        int[] numbers = new int[7];
        for (int i = 0; i < 6; i++) {
            numbers[i] = redBalls.get(i);
        }
        numbers[6] = blueBall;
        return numbers;
    }

    public static int[] getUserInput() {
        Scanner scanner = new Scanner(System.in);
        List<Integer> redBalls = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            int num;
            do {
                System.out.print("请输入红球号码，输入任意一个范围1-33的数字：");
                num = scanner.nextInt();
            } while (num < 1 || num > 33 || redBalls.contains(num));
            redBalls.add(num);
        }
        int blueBall;
        do {
            System.out.print("请输入蓝球号码，输入任意一个范围1-16的数字：");
            blueBall = scanner.nextInt();
        } while (blueBall < 1 || blueBall > 16);

        int[] numbers = new int[7];
        for (int i = 0; i < 6; i++) {
            numbers[i] = redBalls.get(i);
        }
        numbers[6] = blueBall;
        return numbers;
    }

    public static int countRedBallMatch(int[] winning, int[] user) {
        int count = 0;
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 6; j++) {
                if (winning[i] == user[j]) {
                    count++;
                }
            }
        }
        return count;
    }

    public static String determinePrizeLevel(int redMatch, int blueMatch) {
        if (redMatch == 6 && blueMatch == 1) {
            return "恭喜您，中了一等奖！";
        } else if (redMatch == 6 && blueMatch == 0) {
            return "恭喜您，中了二等奖！";
        } else if (redMatch == 5 && blueMatch == 1) {
            return "恭喜您，中了三等奖！";
        } else if (redMatch == 5 && blueMatch == 0 || redMatch == 4 && blueMatch == 1) {
            return "恭喜您，中了四等奖！";
        } else if (redMatch == 4 && blueMatch == 0 || redMatch == 3 && blueMatch == 1) {
            return "恭喜您，中了五等奖！";
        } else if (redMatch == 2 && blueMatch == 1 || redMatch == 1 && blueMatch == 1 || redMatch == 0 && blueMatch == 1) {
            return "恭喜您，中了六等奖！";
        } else {
            return "很遗憾，您未中奖！";
        }
    }

    public static void printNumbers(int[] numbers) {
        for (int num : numbers) {
            System.out.print(num + ",");
        }
        System.out.println();
    }
}

